const equal = require("./template.js")

function testEqual() {
  console.log(
    "1. 基本类型:",
    equal(1, 1) === true &&
      equal("a", "a") === true &&
      equal(null, null) === true
  )

  console.log(
    "2. NaN比较:",
    equal(NaN, NaN) === true && equal(NaN, 0) === false
  )

  console.log(
    "3. 对象比较:",
    equal({ a: 1 }, { a: 1 }) === true && equal({ a: 1 }, { a: 2 }) === false
  )

  console.log(
    "4. 循环引用:",
    (() => {
      const obj1 = { a: 1 }
      obj1.self = obj1
      const obj2 = { a: 1 }
      obj2.self = obj2
      return equal(obj1, obj2) === true
    })()
  )

  console.log(
    "5. 特殊类型:",
    equal([1, 2], [1, 2]) === true &&
      equal(
        () => {},
        () => {}
      ) === false &&
      equal(Symbol(), Symbol()) === false
  )

  console.log(
    "6. this上下文测试:",
    (() => {
      const obj = {
        data1: { a: 1, b: 2 },
        data2: { a: 1, b: 2 },
        compare: function() {
          return equal(this.data1, this.data2)
        }
      }
      return obj.compare() === true
    })()
  )

  console.log(
    "7. 方法调用this绑定:",
    (() => {
      const obj = {
        multiplier: 2,
        process: function(a, b) {
          const modifiedA = { value: a.value * this.multiplier }
          const modifiedB = { value: b.value * this.multiplier }
          return equal(modifiedA, modifiedB)
        }
      }
      const result = obj.process({ value: 1 }, { value: 1 })
      return result === true
    })()
  )

  console.log(
    "8. 复杂对象this绑定:",
    (() => {
      const obj = {
        items: [
          { id: 1, name: "A" },
          { id: 2, name: "B" }
        ],
        compare: function() {
          return equal(this.items[0], { id: 1, name: "A" })
        }
      }
      return obj.compare() === true
    })()
  )
}

testEqual()
